//
//  LGConsultEvaluationCell.m
//  HeartDisease_YHJK
//
//  Created by Bovin on 2025/11/4.
//  聊天页面-发送评估

#import "LGConsultEvaluationCell.h"

@interface LGConsultEvaluationCell()
/**   */
@property (nonatomic , strong)LGCustomCellData *cellData;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)NSMutableArray *buttonArray;
/**   */
@property (nonatomic , strong)NSArray *evaArray;

@end

@implementation LGConsultEvaluationCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.container addSubview:self.baseView];
        [self.baseView addSubview:self.titleLabel];
        [self.baseView addSubview:self.lineView];
    }
    return  self;
}

-(void)fillWithData:(LGCustomCellData *)data{
    [super fillWithData:data];
    self.cellData = data;
    NSDictionary *dataDic = data.customDic[@"msgcontent_doctor"];
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
    self.evaArray = dataDic[@"scales"];
    for (UIView *view in self.buttonArray) {
        [view removeFromSuperview];
    }
    [self.buttonArray removeAllObjects];

    for (NSInteger i=0; i<self.evaArray.count; i++) {
        NSDictionary *tempDic = self.evaArray[i];
        UIButton *button = [UIButton buttonWithTitle:LGNSString(tempDic[@"title"]) titleFont:LGFont(14) textColor:@"#333333" frame:CGRectMake(viewPix(12), viewPix(45)+viewPix(30)*i, Screen_W-viewPix(124), viewPix(30))];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
        [button addTarget:self action:@selector(evaButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 1000+i;
        [self.baseView addSubview:button];
        UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
        [button addSubview:iconView];
        [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.centerY.equalTo(button);
            make.width.height.equalTo(@(16));
        }];
        [self.buttonArray addObject:button];
    }
}

-(void)evaButtonTouched:(UIButton *)sender{
    NSInteger index = sender.tag-1000;
    NSString *urlStr = LGNSString(self.evaArray[index][@"url"]);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckEvaluationDetail" object:nil userInfo:@{@"urlStr":urlStr}];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat height = self.container.size.height;
    if(self.cellData.direction == MsgDirectionIncoming){
        self.baseView.frame = CGRectMake(0, 0, Screen_W-viewPix(100), height);
    }else{
        self.baseView.frame = CGRectMake(self.container.frame.size.width-(Screen_W-viewPix(100)), 0, Screen_W-viewPix(100), height);
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(NSMutableArray *)buttonArray{
    if(!_buttonArray){
        _buttonArray = [NSMutableArray array];
    }
    return _buttonArray;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(12), viewPix(10), Screen_W-viewPix(124), viewPix(20));
    }
    return _titleLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(124), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}


@end
